Repository navigation
Collecting terminals clear their value rows when no pool is offered - #286
Merged
Merged
Conversation
`ToList`, `ToArray`, `ToImmutableArray`, `ToHashSet` and the dictionaries, asynchronous and synchronous, on a view or on a `DbDataReader`, copy their rows out and never show their pooled arrays. They hide their pooling, so a query that does not call `UsePool` now always clears the used rows of those arrays before they go back, plain value rows included, and the app-wide switch cannot turn that off. `UsePool(pool, clearOnReturn)` is followed as before. Rows that hold references were always cleared. The buffers and the streams keep their rule (references, then the query, then the switch). The chunk chain and the array sink release through a new `ChunkConfig.SealCopyOut`, which reads `CopyOutClearOnReturn` (`PoolClearing.ResolveCopyOut`: what `UsePool` said, otherwise clear). A chunk of 128 KB or more is still cleared in the recycle bin, so the read path gains no inline clear for large results. The bytes per call of `ToArrayAsync` and `ToImmutableArrayAsync` on a reader (0, 1, 1,000 and 100,000 rows) are the same before and after. Tests: the rule, the chain and the array sink with no pool, `UsePool(true)` and `UsePool(false)`, in place and in the bin, a row type with references through the chain's copy-out, and the collecting terminals of a view, asynchronous and synchronous, with no pool offered, `UsePool(true)` and `UsePool(false)`. The no-pool cases fail on the old code. Docs: pooled memory remarks, the async buffers article, the pooling and clearing article, the deck notes, `UsePool`, `ChunkConfig`, and the release notes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The collecting terminals hide their pooling, so with no pool offered they now always clear the rows they used.
ToList,ToArray,ToImmutableArray,ToHashSetand the dictionaries (asynchronous and synchronous, on a view or on aDbDataReader) copy their rows out and never show their pooled arrays. A query that does not callUsePoolnow clears the used rows of those arrays before they go back, plain value rows included, and theClearPooledArraysswitch cannot turn that off.UsePool(pool, clearOnReturn)is followed as before (falsekeeps the rows). Rows that hold references were always cleared. The buffers and the streams keep their rule: references, then the query, then the switch.How
PoolClearing.ResolveCopyOut<T>(bool?)isResolve<T>(clear, all: true): whatUsePoolsaid, otherwise clear, plus the references floor.ChunkConfiggetsCopyOutClearOnReturnandSealCopyOut. The chunk chain (every collector on a view and on a reader) and the array sink (the synchronousToArray) release through it;Sealand the buffer and stream paths are untouched.Cost
Allocation is unchanged: the bytes per call of
ToArrayAsyncandToImmutableArrayAsyncover an in-memory reader (the probe from the previous change) are the same before and after, at 0, 1, 1,000 and 100,000 rows (304, 336, 28,304 and 400,328 bytes forToImmutableArrayAsync; 280, 312, 28,280 and 400,304 forToArrayAsync). I did not run a timing benchmark. The clear is oneSpan.Clearof the rows that were written, about as much memory traffic as the single copy-out; for int rows the chunks are at most 32 KB, so it is cleared where released (about 8 to 20 ns a KB by the measurements recorded inChunkConfig), and a result of 100,000 ints clears about 400 KB. The timing of chain plus clear against aListor builder is for the next timed run.Tests
ResolveCopyOutfor null, true and false, for value rows and for rows with references; the buffer and stream rule unchanged.UsePool(true)andUsePool(false), cleared in place and by the bin.UsePoolsaid.ToListAsync,ToArrayAsync,ToImmutableArrayAsync,ToHashSetAsync, bothToDictionaryAsync, and the synchronousToArray,ToImmutableArray,ToDictionary): no pool offered andUsePool(true)leave no row behind;UsePool(false)leaves them. The synchronousToListgrows a list of its own and rents nothing, so it is not in the list. The no-pool cases fail on the old code (checked by putting the old release back at each of the two sites).Checks
dotnet format styleandanalyzersat--severity inforeport nothing on all 14 projects; the docs build is clean.ChunkConfigcomments; a missing no-pool test at the view level; no test of the synchronous terminals; a reference-rows test that never reached the copy-out release. Dismissed: aUsePool(pool)call without the bool (it does not exist, both arguments are required).Docs: pooled memory remarks, the async buffers article, the pooling and clearing article, the deck notes,
UsePool, and the release notes ("Changes since rc.16").🤖 Generated with Claude Code